import { _decorator, assetManager, Component, director, find, instantiate, Node, Prefab, resources } from 'cc';
import { Constant } from './Scripts/Framework/Const/Constant';
import PrivacyPanel from './Scripts/UI/Panel/PrivacyPanel';
import PrefsManager from './Scripts/Framework/Managers/PrefsManager';
const { ccclass, property } = _decorator;

@ccclass('Health')
export class Health extends Component {

    isRead = false;
    isLoad = false;

    start() {
        this.isRead = localStorage.getItem("AgreePolicy") == "1";
        if (!this.isRead) {
            resources.load("Prefabs/UI/PrivacyPanel", Prefab, (err, res) => {
                if (err) console.log("没找到PrivacyPanel")
                let pre = instantiate(res);
                pre.setParent(find("Canvas"));
                pre.getComponent(PrivacyPanel).cb = () => {
                    this.isRead = true;
                    PrefsManager.SetBool(Constant.Key.AgreePolicy, true);
                    this.Check();
                }
            })
        }
        else this.Check();

        assetManager.loadBundle("TalkingLarry",()=>{
            this.isLoad = true;
            this.Check();
        })
    }

    update(deltaTime: number) {

    }

    Check(){
        if(this.isRead && this.isLoad)
        this.scheduleOnce(() => {
            director.loadScene("MainScene");
        }, 2)
    }
}


